package com.jcfk.eam.controller.mould;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;
import com.jcfk.eam.domain.dto.mould.EamMouldEmailRecordFileDTO;
import com.jcfk.eam.domain.query.mould.EamMouldEmailRecordFileQuery;
import com.jcfk.eam.service.mould.EamMouldEmailRecordFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 模具报警记录工单文件
 *
 * @author ly
 * @email 522891237@gqq.com
 * @date 2025-08-13
 */
@Api(tags = {"模具报警记录工单文件管理"})
@RestController
@RequestMapping("eammouldemailrecordfile")
public class EamMouldEmailRecordFileController {
    @Autowired
    private EamMouldEmailRecordFileService eamMouldEmailRecordFileService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamMouldEmailRecordFileQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询模具报警记录工单文件")
    @PostMapping("/queryByPage")
    public RetPage<EamMouldEmailRecordFileDTO> queryByPage(@RequestBody ReqPageParam<EamMouldEmailRecordFileQuery> requestParam) {
        DataPage<EamMouldEmailRecordFileDTO> page = new DataPage<EamMouldEmailRecordFileDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
                EamMouldEmailRecordFileDTO.class);
        page = eamMouldEmailRecordFileService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     * 模具报警记录工单文件
     * 根据id 查询详情
     */
    @ApiOperation("查询模具报警记录工单文件")
    @GetMapping("/get/{id}")
    public RetResult<EamMouldEmailRecordFileDTO> get(@PathVariable("id") String id) {
        EamMouldEmailRecordFileDTO item = eamMouldEmailRecordFileService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理模具报警记录工单文件
     */
    @ApiOperation("保存模具报警记录工单文件")
    @PostMapping("/save")
    @RequestLogHeader(modular = "模具报警记录工单文件管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamMouldEmailRecordFileDTO eamMouldEmailRecordFile) {
        // 数据校验
        RetResult ret = eamMouldEmailRecordFileService.isValid(eamMouldEmailRecordFile);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamMouldEmailRecordFile.getId())) {
            // 新增
            eamMouldEmailRecordFileService.insert(eamMouldEmailRecordFile);
        } else {
            // 更新
            eamMouldEmailRecordFileService.update(eamMouldEmailRecordFile);
        }
        return RetResult.ok();

    }

    /**
     * 批量删除模具报警记录工单文件
     */
    @ApiOperation("批量删除模具报警记录工单文件")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "模具报警记录工单文件管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamMouldEmailRecordFileDTO eamMouldEmailRecordFile) {
        return RetResult.ok(eamMouldEmailRecordFileService.logicDeleteList(eamMouldEmailRecordFile));
    }


    /**
     * 删除模具报警记录工单文件
     */
    @ApiOperation("删除模具报警记录工单文件")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "模具报警记录工单文件管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamMouldEmailRecordFileService.deleteItem(id);
        return RetResult.ok();
    }
}
